<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    
    <div class="layui-form layuimini-form">
        <form action="" class="layui-form" lay-filter="healthForm">
        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-inline ">
                <input type="text" name="health_name" placeholder="请输入姓名" value="" class="layui-input">
                <tip>请填写姓名。</tip>
            </div>
        </div>
                        <input type="hidden" name="health_id">
        <!-- <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-inline">
                <input type="text" name="health_sex" placeholder="请输入性别" value="" class="layui-input">
            </div>
        </div> -->

        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-inline">
                <select name="health_sex" lay-verify="">
                    <!-- <option value="">请选择性别</option> -->
                    <option value="女">女</option>
                    <option value="男">男</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="number" name="health_age" placeholder="请输入年龄" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">身高</label>
            <div class="layui-input-inline">
                <input type="number" name="health_stature" placeholder="请输入身高" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">体重</label>
            <div class="layui-input-inline">
                <input type="number" name="health_weight" placeholder="请输入体重" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">血压</label>
            <div class="layui-input-inline">
                <input type="text" name="health_bp" placeholder="请输入血压" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
    </div>
    </div>
    <!-- <script id="pic">
        <img src="armariumObj.armarium_img" name="armarium_img" style="width:100%; height:100%;" />
    </script> -->
    <script>
        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                upload = layui.upload,
                element = layui.element,
                layer = layui.layer,
                $ = layui.$;

            //从localStorage 把数据取出来  赋值给表单项
            var jsonStr = localStorage.getItem("health");
            var healthObj = JSON.parse(jsonStr);
            console.log(healthObj)
            //给表单项赋值
            form.val("healthForm", {
                health_id: healthObj.health_id,
                health_name: healthObj.health_name,
                health_sex: healthObj.health_sex,
                health_age: healthObj.health_age,
                health_stature: healthObj.health_stature,
                health_weight: healthObj.health_weight,
                health_bp: healthObj.health_bp
            })
 

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {

                    // 关闭弹出层
                    layer.close(index);

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });
                $.ajax({
                    url: "http://localhost:8080/medical/health/edit",
                    data: data.field,
                    type: "post",
                    success: function (result) {
                        if (result.code == 0) {

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改成功", { icon: 1 });
                            parent.layer.close(iframeIndex);

                        } else {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改失败",{icon:2});
                            parent.layer.close(iframeIndex);
                        }
                    },
                    dataType: "json"
                })

                return false;
            });

        });
    </script>
</body>

</html>